package com.swh.dao;

import com.alibaba.druid.pool.DruidDataSource;
import com.swh.entity.User;
import org.springframework.dao.DataAccessException;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;

import java.io.IOException;
import java.util.Properties;

/**
 * @Author: swh
 * @Description:
 * @Date: 2020/11/21 18:21
 * @Version: 1.0
 */
public class BaseDao {
    public JdbcTemplate jdbcTemplate;
    public BaseDao(){
        DruidDataSource dataSource = new DruidDataSource();
        dataSource.setUsername("root");

        Properties prop = new Properties();
        try {
            prop.load(BaseDao.class.getClassLoader().getResourceAsStream("jdbc.properties"));
        } catch (IOException e) {
            e.printStackTrace();
        }
        String driverClassName = prop.getProperty("jdbc.driverClassName");
        String url = prop.getProperty("jdbc.url");
        String username = prop.getProperty("jdbc.username");
        String password = prop.getProperty("jdbc.password");

        dataSource.setDriverClassName(driverClassName);
        dataSource.setUrl(url);
        dataSource.setUsername(username);
        dataSource.setPassword(password);

        jdbcTemplate = new JdbcTemplate(dataSource);
    }

}
